﻿namespace MicroCloud.Extensions
{
    /// <summary>
    /// Scoped生命周期字典扩展方法
    /// </summary>
    public static class ScopedDictionaryExtensions
    {
        /// <summary>
        /// 从Scoped字典中获取指定类型的值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dict"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T GetValue<T>(this ScopedDictionary dict, string key) where T : class
        {
            if (dict.TryGetValue(key, out object obj))
            {
                return obj as T;
            }

            return default;
        }

    }
}
